/**
 * 
 */
package jmotioncapture.camera;

import java.util.Vector;

import jmotioncapture.calculation.GeomCalculation;
import jmotioncapture.geometry2D.Line;
import jmotioncapture.geometry2D.Point;
import jmotioncapture.geometry2D.PointComparable;

/**
 * A collection of points which have the same capturing time
 * 
 * @author Kenneth Lo
 * 
 */
public class Frame {

	/**
	 * Collections of point
	 */
	private Vector<Point> points = new Vector<Point>(10, 5);;

	/**
	 * Capturing time
	 */
	private long captureTime;

	public Frame()
	{
		captureTime = -1;
	}
	
	/**
	 * 
	 * @param points
	 */
	public Frame(Vector<Point> points, long captureTime) {
		this.points = points;
		this.captureTime = captureTime;
	}

	/**
	 * Add point to the frame
	 * 
	 * @param point
	 */
	public void addPoint(Point point) {
		this.points.addElement(point);
	}

	/**
	 * Return the number of points included in the frame
	 * 
	 * @return
	 */
	public int getNumberOfPoints() {
		return this.points.size();
	}

	/**
	 * Clear all the points in the frame
	 */
	public void removeAllPoint() {
		this.points.removeAllElements();
	}

	/**
	 * Return all the points in the Frame
	 * 
	 * @return
	 */
	public Vector<Point> getPoints() {
		return this.points;
	}

	/**
	 * Return the specific index of point
	 * 
	 * @return
	 */
	public Point getPoint(int index) {
		return this.points.elementAt(index);
	}

	/**
	 * Return the capture time of this frame
	 * 
	 * @return
	 */
	public long getCaptureTime() {
		return captureTime;
	}

	/**
	 * Get the points which bounded the maximun area and sorted clockwise.
	 * 
	 * @return
	 */
	public Vector<Point> getMaximunAreaBoundPoints() {

		return GeomCalculation.giftWrappingBound(this.points);
	}

	/**
	 * Get all the combination of lines
	 * 
	 * @return
	 */
	public Vector<Line> getLines() {
		return GeomCalculation.getLines(this.points);
	}

	public PointComparable[] sortPointsByX() {
		return GeomCalculation.sortPointsByX(this.points);
	}

	public PointComparable[] sortPointsByY() {
		return GeomCalculation.sortPointsByY(this.points);
	}

	public double maxBoundedArea() {
		return GeomCalculation.nPointsArea(points, false);
	}
}
